<template>
    <a-modal :title="$t('编辑保护网关')" v-model='isShow' @cancel='handleClose' width='480px' @ok='handleCreate'
        :cancelText="$t('Cancel')" :okText="$t('Sure')" :maskClosable='false' v-dragModal>
        <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol">
            <a-spin :spinning="loading">
                <a-form-model-item :label="$t('名称') + ':'" prop="name">
                    <a-input v-model="form.name" :placeholder="$t('Enter') + $t('名称')" />
                </a-form-model-item>
                <a-form-model-item :label="$t('保护网关节点') + ':'" prop="info">
                    <a-select disabled v-model="form.info" :placeholder="$t('Choose') + $t('保护网关节点')">
                        <a-select-option :value="form.info">
                            {{ form.info }}
                        </a-select-option>
                    </a-select>
                </a-form-model-item>
            </a-spin>
        </a-form-model>
    </a-modal>
</template>

<script>
export default {
    data() {
        return {
            isShow: false,
            loading: false,
            labelCol: { span: 6 },
            wrapperCol: { span: 18 },
            form: {
                name: '',
                info: '',
                id: '',
            },
            rules: {
                name: [
                    { required: true, message: this.$t('Enter') + this.$t('名称'), trigger: 'blur' },
                    { pattern: /^[A-Za-z0-9_]{1,128}$/, message: this.$t('支持大小写英文字母 + 数字 + 英文下划线，1-128 个字符'), trigger: 'blur' }
                ],
            },
            gatewayOption: [],
        };
    },
    methods: {
        handleCreate() {
            this.$refs.ruleForm.validate(async valid => {
                if (valid) {
                    const { id, name } = this.form
                    const { data } = await this.$api.data.modifyGatewayListApi(({ id, name }))
                    this.model(data.id) //返回模板
                    this.notice(data.id, data.params, data.flag) //通知列表显示
                    if (data.flag == '0') {
                        this.$emit('get-list')
                        this.handleClose()
                    }
                } else {
                    return false;
                }
            });
        },
        handleClose() {
            this.$refs['ruleForm'].resetFields();
            this.isShow = false
        },
    }
}
</script>
